package com.example.s05_shop.config;

import com.example.s05_shop.servlet.TestServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.ServletRegistration;

// 编写了一个配置类
// @Configuration

// 支持Servlet的方式二 编写一个配置一类实现 WebMvcConfigurer接口
// 返回一个注册Servlet的对象 ServletRegistrationBean

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Bean
    public ServletRegistrationBean servletRegistration()
    {
        return new ServletRegistrationBean(new TestServlet(),"/test");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry)
    {
        System.out.println("配置图片外部路径");
        registry.addResourceHandler("/images/**")  // 网址访问的路径
                .addResourceLocations("file:" +"./upload/" );   //  图片存放的路径
    }


}
